/*
 * Copyright 2014 alexpad@gmail.com.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package alexpad.karaokarc.gui;

import alexpad.karaokarc.i18n.I18N;
import java.awt.Component;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.exception.ExceptionUtils;

/**
 * 
 * @author alexpad@gmail.com
 */
public class DialogHelper {
	
	public static final int OPTION_NO = 1;
	public static final int OPTION_YES = 0;
	
	private static final Object[] YES_NO_OPTIONS = {
		I18N.getString("generic.option.yes"), I18N.getString("generic.option.no")
	};
	
	public static void showInfo(Component parent, String message){
		JOptionPane.showMessageDialog(parent, message, I18N.getString("dialog.infoMessage.title"), JOptionPane.INFORMATION_MESSAGE);
	}
	
	public static void showWarning(Component parent, String message){
		JOptionPane.showMessageDialog(parent, message, I18N.getString("dialog.warnMessage.title"), JOptionPane.WARNING_MESSAGE);
	}
	
	public static void showError(Component parent, Throwable t, boolean stackTrace){
		String message = t.toString();
		if(stackTrace){
			message = ExceptionUtils.getStackTrace(t);
		}
		JOptionPane.showMessageDialog(parent, I18N.getString("generic.unexpectedError", message), I18N.getString("dialog.errorMessage.title"), JOptionPane.ERROR_MESSAGE);
	}
	
	public static int showYesNoQuestion(Component parent, String question, int defaultOption){
		return JOptionPane.showOptionDialog(
			parent,
			question,
			I18N.getString("dialog.questionMessage.title"),
			JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, YES_NO_OPTIONS, YES_NO_OPTIONS[defaultOption%1]
		);
	}
}
